<template>
	<view>
		
		<view style="padding-bottom:100rpx;">
			<view v-for="(item, index) in pageList" :key="index">
				<view class="bb px15 py10 dis-flex flex-between" v-if="item.type == 1" @tap="chooseImage(index)">
					<view class="dis-flex">
						<view class="c-333 fs14" style="width: 190rpx;">{{item.value}}</view>
						<view class="fs14 c-common" v-if="item[item.title]" @click.stop="fileLook(item[item.title])">点击查看</view>
						<view class="fs14" style="color: #C4C4CC;" v-else>请选择文件</view>
					</view>
					<u-icon name="arrow-right" color="#C4C4CC" size="28" label-size="28"></u-icon>
				</view>
				<view class="bb px15 py10" v-else>
					<u-input :placeholder="'请输入'+item.value" border="none" v-model="item[item.title]" fontSize="30" :clearable="true"
						type="text" maxlength="30">
						<view class="c-333 fs14 dis-flex" slot="prefix" style="width: 190rpx;">{{item.value}}</view>
					</u-input>
				</view>
			</view>
		</view>
		<view class="btn-submit-box">
			<button class="btn-submit bg-common c-fff" :loading="loginLoading"  @tap="addSubmit">确定</button>
		</view>
	</view>
</template>

<script>
	import validate from "@/common/thformvalidate";
	export default {
		data() {
			return {
				id:'',
				pageList:[],
				index:0,
				loginLoading:false,
			}
		},
		
		onLoad(option){
			this.id = option.id || '';
			this.getDetail();
		},
		
		methods: {
			
			getDetail() {
				this.$http.post(this.$config.UrlGetExtend,{
					ids:this.id
				},{log:true,
					header: {
					'content-type': 'application/json'
				}}).then((res) => {
					let mList = res.data || [];	
					mList.forEach(item=>{
						item[item.title] = ''
					})
					
					this.pageList = mList;
				})
			},
			
			chooseImage(index) {
				this.index = index;
				uni.chooseFile({
					count: 1,
					success: (res) => {
						this.uploadImage(res.tempFilePaths[0]);
					}
				});
			},
			uploadImage(tempFilePaths) {
				this.$http.upload(this.$config.UrlSignUpload, {
					filePath: tempFilePaths,
					name: 'file',
					formData: {},
				}).then((res) => {
					if (res.code == 1) {
						let mItem = this.pageList[this.index];
						mItem[mItem.title] = res?.data?.url;
					} else this.$api.toast(res.msg);
				})
			},
			
			fileLook(src){
				this.$api.openWindow('/pages/center/fileLook?src='+src);
			},
			
			addSubmit(){
				let mData = {};
				this.pageList.forEach(item=>{
					mData[item.title] = item[item.title]
				})
				mData.ids = this.id;
				this.loginLoading = true;
				this.$http.post(this.$config.UrlContractEdit, mData, {
					log: true,
					header: {
						'content-type': 'application/json'
					}
				}).then((res) => {
					this.$api.toast(res.msg);
					if(res.code == 1){
						this.$api.opener().refreshList();
						this.$api.back();
					}
				}).finally((res) => {
					this.loginLoading = false;
				})
			},
		}
	}
</script>

<style >
	page{
		background: #fff;
	}
	.popView{width:650rpx;padding-bottom: 20rpx;}
	.btn-minis{border-radius: 40rpx;height: 50rpx;;line-height: 50rpx;font-size: 26rpx;min-width: 100rpx;}
</style>
